{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from configs.params import ESParams\n",
    "from elasticsearch import Elasticsearch\n",
    "\n",
    "es_params = ESParams()\n",
    "index_name = es_params.index_name"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### openai Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import openai\n",
    "# import numpy as np\n",
    "# openai.api_key = \"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\"\n",
    "# text = '你吃了早餐没？'\n",
    "# def getEmbedding(text):\n",
    "#     sentence_embeddings = openai.Embedding.create(\n",
    "#         model=\"text-embedding-ada-002\",\n",
    "#         input=text\n",
    "#     )    \n",
    "#     data = sentence_embeddings[\"data\"][0][\"embedding\"]\n",
    "#     return data\n",
    "# def cossim(vec1, vec2):\n",
    "#     cos_sim = vec1.dot(vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2))\n",
    "#     return cos_sim\n",
    "# data1 = getEmbedding(text)\n",
    "# # data2 = getEmbedding(\"你早上吃了没？\")\n",
    "# # data3 = getEmbedding(\"你晚上吃了没？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "N\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Jack\\AppData\\Local\\Temp\\ipykernel_20988\\1228161630.py:3: ElasticsearchWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.\n",
      "  if client.indices.exists(index=\"test\"):\n"
     ]
    }
   ],
   "source": [
    "es_host = \"http://localhost:9200\"\n",
    "client = Elasticsearch(es_host)\n",
    "if client.indices.exists(index=\"test\"):\n",
    "    print('Y')\n",
    "else:\n",
    "    print(\"N\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openai\n",
    "openai.api_key = \"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\"\n",
    "text = '已知信息：\\n今天早上，我参加了工程伦理领读课程，由几位报名的小组同学进行内容分享。他们的分享让我对《素质教育与前沿技术》这门课程有了更深刻的理解。课程内容 \\\n",
    "涵盖了六个主题，每个主题都深入探讨了工程伦理的不同方面。通过分析真实的案例，我认识到伦理决策的重要性，并学会了如何从伦理的角度分析问题，以便做出符合道德标准的决策。同时，我也了解到实践伦理 \\\n",
    "工具箱的重要性，它为工程师提供了一系列方法和工具来应对伦理挑战。这些工具不仅有助于解决问题，还能帮助工程师更好地理解和管理伦理风险。此外，课程还强调了工程师的责任，包括对他们的工作承担道德 \\\n",
    "和法律责任。这一主题教导我们如何在工程实践中积极履行职业道德。同时，我也认识到工程师不仅是技术专家，还需要考虑他们的工作对社会和价值观的影响。建立信任关系在工程领域中的重要性也得到了强调， \\\n",
    "工程师应该努力提供可靠的解决方案，以维护客户和社会对他们的信任。最后，课程还探讨了工程风险与责任的问题，强调了工程师在面对潜在风险时应该如何行动。总之，这门课程使我深刻地认识到工程伦理对于 \\\n",
    "工程师的重要性。工程师不仅是技术专家，还是社会的一部分，他们的工作对社会和环境有深远的影响。因此，了解和积极践行职业道德是至关重要的。\\n \\n\\n根据上述已知信息，简洁和专业的来回答用户的问题。\\\n",
    "如果无法从中得到答案，请说 “根据已知信息无法回答该问题” 或 “没有提供足够的相关信息”，不允许在答案中添加编造成分，答案请使用中文。 问题是：你好'\n",
    "# gpt_answer = openai.ChatCompletion.create(\n",
    "#     temperature=0.7,\n",
    "#     model=\"gpt-3.5-turbo\",\n",
    "#     prompt=text,\n",
    "# )\n",
    "model_engine = \"text-davinci-003\"\n",
    "completion = openai.Completion.create(\n",
    "    engine=model_engine,\n",
    "    prompt=text,\n",
    "    max_tokens=1024,\n",
    "    n=1,\n",
    "    stop=None,\n",
    "    temperature=0.5,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def prompt(question, answers):\n",
    "    \"\"\"\n",
    "    生成对话的示例提示语句，格式如下：\n",
    "    demo_q:\n",
    "    使用以下段落来回答问题，如果段落内容不相关就返回未查到相关信息：\"成人头疼，流鼻涕是感冒还是过敏？\"\n",
    "    1. 普通感冒：您会出现喉咙发痒或喉咙痛，流鼻涕，流清澈的稀鼻涕（液体），有时轻度发热。\n",
    "    2. 常年过敏：症状包括鼻塞或流鼻涕，鼻、口或喉咙发痒，眼睛流泪、发红、发痒、肿胀，打喷嚏。\n",
    "    demo_a:\n",
    "    成人出现头痛和流鼻涕的症状，可能是由于普通感冒或常年过敏引起的。如果病人出现咽喉痛和咳嗽，感冒的可能性比较大；而如果出现口、喉咙发痒、眼睛肿胀等症状，常年过敏的可能性比较大。\n",
    "    system:\n",
    "    你是一个医院问诊机器人\n",
    "    \"\"\"\n",
    "    demo_q = '使用以下段落来回答问题：\"成人头疼，流鼻涕是感冒还是过敏？\"\\n1. 普通感冒：您会出现喉咙发痒或喉咙痛，流鼻涕，流清澈的稀鼻涕（液体），有时轻度发热。\\n2. 常年过敏：症状包括鼻塞或流鼻涕，鼻、口或喉咙发痒，眼睛流泪、发红、发痒、肿胀，打喷嚏。'\n",
    "    demo_a = '成人出现头痛和流鼻涕的症状，可能是由于普通感冒或常年过敏引起的。如果病人出现咽喉痛和咳嗽，感冒的可能性比较大；而如果出现口、喉咙发痒、眼睛肿胀等症状，常年过敏的可能性比较大。'\n",
    "    system = '你是一个医院问诊机器人'\n",
    "    q = '使用以下段落来回答问题，如果段落内容不相关就返回未查到相关信息：\"'\n",
    "    q += question + '\"'\n",
    "    # 带有索引的格式\n",
    "    # for index, answer in enumerate(answers):\n",
    "    #     q += str(index + 1) + '. ' + str(answer['title']) + ': ' + str(answer['text']) + '\\n'\n",
    "    for index, answer in enumerate(answers):\n",
    "        q += str(index + 1) + '. ' + str(answer['text']) + '\\n'\n",
    "    \"\"\"\n",
    "    system:代表的是你要让GPT生成内容的方向，在这个案例中我要让GPT生成的内容是医院问诊机器人的回答，所以我把system设置为医院问诊机器人\n",
    "    前面的user和assistant是我自己定义的，代表的是用户和医院问诊机器人的示例对话，主要规范输入和输出格式\n",
    "    下面的user代表的是实际的提问\n",
    "    \"\"\"\n",
    "    res = [\n",
    "        {'role': 'system', 'content': system},\n",
    "        {'role': 'user', 'content': demo_q},\n",
    "        {'role': 'assistant', 'content': demo_a},\n",
    "        {'role': 'user', 'content': q},\n",
    "    ]\n",
    "    return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'role': 'system', 'content': '你是一个医院问诊机器人'},\n",
       " {'role': 'user',\n",
       "  'content': '使用以下段落来回答问题：\"成人头疼，流鼻涕是感冒还是过敏？\"\\n1. 普通感冒：您会出现喉咙发痒或喉咙痛，流鼻涕，流清澈的稀鼻涕（液体），有时轻度发热。\\n2. 常年过敏：症状包括鼻塞或流鼻涕，鼻、口或喉咙发痒，眼睛流泪、发红、发痒、肿胀，打喷嚏。'},\n",
       " {'role': 'assistant',\n",
       "  'content': '成人出现头痛和流鼻涕的症状，可能是由于普通感冒或常年过敏引起的。如果病人出现咽喉痛和咳嗽，感冒的可能性比较大；而如果出现口、喉咙发痒、眼睛肿胀等症状，常年过敏的可能性比较大。'},\n",
       " {'role': 'user',\n",
       "  'content': '使用以下段落来回答问题，如果段落内容不相关就返回未查到相关信息：\"早上好\"1. 早上好是中国打招呼的方式\\n2. Good morning\\n'}]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "question = \"早上好\"\n",
    "answers = [{'text':\"早上好是中国打招呼的方式\"}, {'text':'Good morning'}]\n",
    "text = prompt(question, answers)\n",
    "text\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "gpt_answer = openai.ChatCompletion.create(\n",
    "    temperature=0.7,\n",
    "    model=\"gpt-3.5-turbo\",\n",
    "    messages=text,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'早上好是中国打招呼的方式。'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gpt_answer.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'，这门课程主要讲了什么？\\n\\n这门课程涵盖了六个主题，每个主题都深入探讨了工程伦理的不同方面，包括伦理决策的重要性、实践伦理工具箱、工程师的责任、建立信任关系和工程风险与责任等。'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "completion.choices[0].text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class ES:\n",
    "    def __init__(self, embedding_model_path):\n",
    "        self.es_params = ESParams()\n",
    "        # self.client = Elasticsearch(['{}:{}'.format(self.es_params.url, self.es_params.port)],\n",
    "        #                             basic_auth=(self.es_params.username, self.es_params.passwd),\n",
    "        #                             verify_certs=False)\n",
    "        self.client = Elasticsearch('{}:{}'.format(self.es_params.url, self.es_params.port))\n",
    "        self.embedding = Embeddings(embedding_model_path)\n",
    "        self.es = ElasticKnnSearch(index_name=self.es_params.index_name, embedding=self.embedding,\n",
    "                                   es_connection=self.client)\n",
    "\n",
    "    def doc_upload(self, file_obj, chunk_size, chunk_overlap):\n",
    "        try:\n",
    "            if not self.client.indices.exists(index=self.es_params.index_name):\n",
    "                dims = len(self.embedding.embed_query(\"test\"))\n",
    "                # mapping = _default_knn_mapping(dims)\n",
    "                self.client.indices.create(index=self.es_params.index_name, body={\"mappings\": mapping})\n",
    "            filename = os.path.split(file_obj.name)[-1]\n",
    "            file_path = 'data/' + filename\n",
    "            shutil.move(file_obj.name, file_path)\n",
    "            docs = load_file(file_path, chunk_size, chunk_overlap)\n",
    "            self.es.add_documents(docs)\n",
    "            return \"插入成功\"\n",
    "        except Exception as e:\n",
    "            return e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://localhost 9200 vectorbase 123456\n"
     ]
    }
   ],
   "source": [
    "print(es_params.url, es_params.port, es_params.username, es_params.passwd)\n",
    "client = Elasticsearch(['{}:{}'.format(es_params.url, es_params.port)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Jack\\AppData\\Local\\Temp\\ipykernel_4920\\2899389431.py:3: ElasticsearchWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.\n",
      "  if es.indices.exists(index=\"myindex\"):\n"
     ]
    }
   ],
   "source": [
    "es_host = \"http://localhost:9200\"\n",
    "es = Elasticsearch(es_host)\n",
    "if es.indices.exists(index=\"myindex\"):\n",
    "    es.indices.delete(index=\"myindex\")\n",
    "else:\n",
    "    print('hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Jack\\AppData\\Local\\Temp\\ipykernel_4920\\2803272245.py:1: ElasticsearchWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.\n",
      "  es.ping()\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "es.ping()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "TlsError",
     "evalue": "TLS error caused by: TlsError(TLS error caused by: SSLError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)))",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTlsError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32md:\\学习文件\\研究生\\python\\project\\ElasticSearch-Langchain-Chatglm2-main\\ElasticSearch-Langchain-Chatglm2-main\\test.ipynb Cell 4\u001b[0m line \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/d%3A/%E5%AD%A6%E4%B9%A0%E6%96%87%E4%BB%B6/%E7%A0%94%E7%A9%B6%E7%94%9F/python/project/ElasticSearch-Langchain-Chatglm2-main/ElasticSearch-Langchain-Chatglm2-main/test.ipynb#W3sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m result \u001b[39m=\u001b[39m client\u001b[39m.\u001b[39;49mindices\u001b[39m.\u001b[39;49mcreate(index\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mnews\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[0;32m      <a href='vscode-notebook-cell:/d%3A/%E5%AD%A6%E4%B9%A0%E6%96%87%E4%BB%B6/%E7%A0%94%E7%A9%B6%E7%94%9F/python/project/ElasticSearch-Langchain-Chatglm2-main/ElasticSearch-Langchain-Chatglm2-main/test.ipynb#W3sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mprint\u001b[39m(result)\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elasticsearch\\_sync\\client\\utils.py:402\u001b[0m, in \u001b[0;36m_rewrite_parameters.<locals>.wrapper.<locals>.wrapped\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m    399\u001b[0m         \u001b[39mexcept\u001b[39;00m \u001b[39mKeyError\u001b[39;00m:\n\u001b[0;32m    400\u001b[0m             \u001b[39mpass\u001b[39;00m\n\u001b[1;32m--> 402\u001b[0m \u001b[39mreturn\u001b[39;00m api(\u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elasticsearch\\_sync\\client\\indices.py:493\u001b[0m, in \u001b[0;36mIndicesClient.create\u001b[1;34m(self, index, aliases, error_trace, filter_path, human, mappings, master_timeout, pretty, settings, timeout, wait_for_active_shards)\u001b[0m\n\u001b[0;32m    491\u001b[0m \u001b[39mif\u001b[39;00m __body \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m    492\u001b[0m     __headers[\u001b[39m\"\u001b[39m\u001b[39mcontent-type\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mapplication/json\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m--> 493\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mperform_request(  \u001b[39m# type: ignore[return-value]\u001b[39;49;00m\n\u001b[0;32m    494\u001b[0m     \u001b[39m\"\u001b[39;49m\u001b[39mPUT\u001b[39;49m\u001b[39m\"\u001b[39;49m, __path, params\u001b[39m=\u001b[39;49m__query, headers\u001b[39m=\u001b[39;49m__headers, body\u001b[39m=\u001b[39;49m__body\n\u001b[0;32m    495\u001b[0m )\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elasticsearch\\_sync\\client\\_base.py:389\u001b[0m, in \u001b[0;36mNamespacedClient.perform_request\u001b[1;34m(self, method, path, params, headers, body)\u001b[0m\n\u001b[0;32m    378\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mperform_request\u001b[39m(\n\u001b[0;32m    379\u001b[0m     \u001b[39mself\u001b[39m,\n\u001b[0;32m    380\u001b[0m     method: \u001b[39mstr\u001b[39m,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    387\u001b[0m     \u001b[39m# Use the internal clients .perform_request() implementation\u001b[39;00m\n\u001b[0;32m    388\u001b[0m     \u001b[39m# so we take advantage of their transport options.\u001b[39;00m\n\u001b[1;32m--> 389\u001b[0m     \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_client\u001b[39m.\u001b[39;49mperform_request(\n\u001b[0;32m    390\u001b[0m         method, path, params\u001b[39m=\u001b[39;49mparams, headers\u001b[39m=\u001b[39;49mheaders, body\u001b[39m=\u001b[39;49mbody\n\u001b[0;32m    391\u001b[0m     )\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elasticsearch\\_sync\\client\\_base.py:285\u001b[0m, in \u001b[0;36mBaseClient.perform_request\u001b[1;34m(self, method, path, params, headers, body)\u001b[0m\n\u001b[0;32m    282\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    283\u001b[0m     target \u001b[39m=\u001b[39m path\n\u001b[1;32m--> 285\u001b[0m meta, resp_body \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtransport\u001b[39m.\u001b[39;49mperform_request(\n\u001b[0;32m    286\u001b[0m     method,\n\u001b[0;32m    287\u001b[0m     target,\n\u001b[0;32m    288\u001b[0m     headers\u001b[39m=\u001b[39;49mrequest_headers,\n\u001b[0;32m    289\u001b[0m     body\u001b[39m=\u001b[39;49mbody,\n\u001b[0;32m    290\u001b[0m     request_timeout\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_request_timeout,\n\u001b[0;32m    291\u001b[0m     max_retries\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_max_retries,\n\u001b[0;32m    292\u001b[0m     retry_on_status\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_retry_on_status,\n\u001b[0;32m    293\u001b[0m     retry_on_timeout\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_retry_on_timeout,\n\u001b[0;32m    294\u001b[0m     client_meta\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_client_meta,\n\u001b[0;32m    295\u001b[0m )\n\u001b[0;32m    297\u001b[0m \u001b[39m# HEAD with a 404 is returned as a normal response\u001b[39;00m\n\u001b[0;32m    298\u001b[0m \u001b[39m# since this is used as an 'exists' functionality.\u001b[39;00m\n\u001b[0;32m    299\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m (method \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mHEAD\u001b[39m\u001b[39m\"\u001b[39m \u001b[39mand\u001b[39;00m meta\u001b[39m.\u001b[39mstatus \u001b[39m==\u001b[39m \u001b[39m404\u001b[39m) \u001b[39mand\u001b[39;00m (\n\u001b[0;32m    300\u001b[0m     \u001b[39mnot\u001b[39;00m \u001b[39m200\u001b[39m \u001b[39m<\u001b[39m\u001b[39m=\u001b[39m meta\u001b[39m.\u001b[39mstatus \u001b[39m<\u001b[39m \u001b[39m299\u001b[39m\n\u001b[0;32m    301\u001b[0m     \u001b[39mand\u001b[39;00m (\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    305\u001b[0m     )\n\u001b[0;32m    306\u001b[0m ):\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elastic_transport\\_transport.py:329\u001b[0m, in \u001b[0;36mTransport.perform_request\u001b[1;34m(self, method, target, body, headers, max_retries, retry_on_status, retry_on_timeout, request_timeout, client_meta)\u001b[0m\n\u001b[0;32m    327\u001b[0m start_time \u001b[39m=\u001b[39m time\u001b[39m.\u001b[39mtime()\n\u001b[0;32m    328\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m--> 329\u001b[0m     meta, raw_data \u001b[39m=\u001b[39m node\u001b[39m.\u001b[39;49mperform_request(\n\u001b[0;32m    330\u001b[0m         method,\n\u001b[0;32m    331\u001b[0m         target,\n\u001b[0;32m    332\u001b[0m         body\u001b[39m=\u001b[39;49mrequest_body,\n\u001b[0;32m    333\u001b[0m         headers\u001b[39m=\u001b[39;49mrequest_headers,\n\u001b[0;32m    334\u001b[0m         request_timeout\u001b[39m=\u001b[39;49mrequest_timeout,\n\u001b[0;32m    335\u001b[0m     )\n\u001b[0;32m    336\u001b[0m     _logger\u001b[39m.\u001b[39minfo(\n\u001b[0;32m    337\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m%s\u001b[39;00m\u001b[39m [status:\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m duration:\u001b[39m\u001b[39m%.3f\u001b[39;00m\u001b[39ms]\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    338\u001b[0m         \u001b[39m%\u001b[39m (\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    344\u001b[0m         )\n\u001b[0;32m    345\u001b[0m     )\n\u001b[0;32m    347\u001b[0m     \u001b[39mif\u001b[39;00m method \u001b[39m!=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mHEAD\u001b[39m\u001b[39m\"\u001b[39m:\n",
      "File \u001b[1;32md:\\Anaconda\\envs\\pytorch\\lib\\site-packages\\elastic_transport\\_node\\_http_urllib3.py:199\u001b[0m, in \u001b[0;36mUrllib3HttpNode.perform_request\u001b[1;34m(self, method, target, body, headers, request_timeout)\u001b[0m\n\u001b[0;32m    191\u001b[0m         err \u001b[39m=\u001b[39m \u001b[39mConnectionError\u001b[39;00m(\u001b[39mstr\u001b[39m(e), errors\u001b[39m=\u001b[39m(e,))\n\u001b[0;32m    192\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_log_request(\n\u001b[0;32m    193\u001b[0m         method\u001b[39m=\u001b[39mmethod,\n\u001b[0;32m    194\u001b[0m         target\u001b[39m=\u001b[39mtarget,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    197\u001b[0m         exception\u001b[39m=\u001b[39merr,\n\u001b[0;32m    198\u001b[0m     )\n\u001b[1;32m--> 199\u001b[0m     \u001b[39mraise\u001b[39;00m err \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[0;32m    201\u001b[0m meta \u001b[39m=\u001b[39m ApiResponseMeta(\n\u001b[0;32m    202\u001b[0m     node\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mconfig,\n\u001b[0;32m    203\u001b[0m     duration\u001b[39m=\u001b[39mduration,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    206\u001b[0m     headers\u001b[39m=\u001b[39mresponse_headers,\n\u001b[0;32m    207\u001b[0m )\n\u001b[0;32m    208\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_log_request(\n\u001b[0;32m    209\u001b[0m     method\u001b[39m=\u001b[39mmethod,\n\u001b[0;32m    210\u001b[0m     target\u001b[39m=\u001b[39mtarget,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    214\u001b[0m     response\u001b[39m=\u001b[39mdata,\n\u001b[0;32m    215\u001b[0m )\n",
      "\u001b[1;31mTlsError\u001b[0m: TLS error caused by: TlsError(TLS error caused by: SSLError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)))"
     ]
    }
   ],
   "source": [
    "result = client.indices.create(index='news')\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
